<?php

ini_set('memory_limit', '1000M');
require_once dirname(__FILE__) . '/loadphplib.php';

$REPORT_FILE = dirname(__FILE__) . '/lockcheckreport.log';

$cmd = "ps -ef | grep php | grep 'bin.sendwl'";
$psef = shell_exec($cmd);


$arrRuning = array();

$arrpsef = explode(PHP_EOL, $psef);
foreach ($arrpsef as $ps) {
    $arrPs = explode('bin.sendwl.php', $ps);
    $arrPs1 = explode(' ', $arrPs[1]);
    $fileflag = $arrPs1[1];
    $iIndex = $arrPs1[2];
    $LOCK_RUN_FILE = dirname(__FILE__) . '/Lock-' . $fileflag . '-' . $iIndex . '.txt';
    $arrRuning[] = $LOCK_RUN_FILE;
}

for ($i = 0; $i <= 100; $i++) {
    for ($j = 0; $j <= 100; $j++) {
        $fileLockFileCheck = dirname(__FILE__) . '/Lock-' . $i . '-' . $j . '.txt';
        if (!in_array($fileLockFileCheck, $arrRuning)) {
            if (file_exists($fileLockFileCheck)) {
                @unlink($fileLockFileCheck);
				file_put_contents($REPORT_FILE, date('Y-m-d H:i:s') . '|' . 'unlink:' . $fileLockFileCheck . PHP_EOL, 8);
            }
        }
    }
}
?>